package com.ky.pro.big.data.mr.mobile.dr;

import com.ky.pro.big.data.mr.mobile.dr.dto.MobileDataRateInfo;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class MobileDataRateReducer extends Reducer<LongWritable, MobileDataRateInfo, LongWritable, MobileDataRateInfo> {

    @Override
    protected void reduce(LongWritable key, Iterable<MobileDataRateInfo> values, Context context) throws IOException, InterruptedException {

        int sumUpRate = 0;
        int sumDownRate = 0;

        for (MobileDataRateInfo drInfo : values) {
            sumUpRate += drInfo.getUpRate();
            sumDownRate += drInfo.getDownRate();
        }

        MobileDataRateInfo sumInfo = new MobileDataRateInfo(key.get(), sumUpRate, sumDownRate);

        context.write(key, sumInfo);

    }
}
